function [circle_1]=cb(circle,tt)
circle_0=circle;
circle_1={}; %circle_1存储合并后的数据
ii=1;k=1;num=0;
while ii<=size(circle_0,1)
    circle_1{ii,1}=circle_0{ii,1};circle_1{ii,2}=circle_0{ii,2};circle_1{ii,3}=circle_0{ii,3};
    j=ii+1;
    while j<=size(circle_0,1)
        center1=circle_0{ii,2};
        center2=circle_0{j,2};
        if pdist([center1(1:2);center2(1:2)])<10 & pdist([center1(3);center2(3)])<10
            circle_1{ii,1}=[circle_0{ii,1};circle_0{j,1}];
            circle_0(j,:)=[];
            j=j-1;
            num=1;
        end
        j=j+1;
    end
    ii=ii+1;
end
% 重新计算拟合参数
if tt==1
    for j=1:1:size(circle_1,1)
        [p,m]=Circle_Fitting(circle_1{j,1}(:,2:3));
        circle_1{j,2}=p;
        circle_1{j,3}=m;
    end
end
if tt==2
    for j=1:1:size(circle_1,1)
        [p,m]=Circle_Fitting(circle_1{j,1}(:,5:6));
        circle_1{j,2}=p;
        circle_1{j,3}=m;
    end
end

function [p,m] = Circle_Fitting( XZ )
N = size(XZ,1);
x = XZ(:,1);
z = XZ(:,2);
sum_X_Raw = 0;
sum_Z_Raw = 0;
sum_XSquare_Raw = 0;
sum_ZSquare_Raw = 0;
sum_XCube_Raw = 0;
sum_ZCube_Raw = 0;
sum_XZZ_Raw = 0;
sum_XZ_Raw = 0;
sum_XXZ_Raw = 0;

for i=1:N
    sum_X_Raw = sum_X_Raw+x(i);
    sum_Z_Raw = sum_Z_Raw+z(i);
    sum_XSquare_Raw = sum_XSquare_Raw+x(i)*x(i);
    sum_ZSquare_Raw = sum_ZSquare_Raw+z(i)*z(i);
    sum_XCube_Raw = sum_XCube_Raw+x(i)*x(i)*x(i);
    sum_ZCube_Raw = sum_ZCube_Raw+z(i)*z(i)*z(i);
    sum_XZ_Raw = sum_XZ_Raw+x(i)*z(i);
    sum_XZZ_Raw = sum_XZZ_Raw+x(i)*z(i)*z(i);
    sum_XXZ_Raw = sum_XXZ_Raw+x(i)*x(i)*z(i);
end
D = N*sum_XZ_Raw-sum_X_Raw*sum_Z_Raw;
C = N*sum_XSquare_Raw-sum_X_Raw*sum_X_Raw;
E = N*sum_XCube_Raw+N*sum_XZZ_Raw-(sum_XSquare_Raw+sum_ZSquare_Raw)*sum_X_Raw;
G = N*sum_ZSquare_Raw-sum_Z_Raw*sum_Z_Raw;
H = N*sum_ZCube_Raw+N*sum_XXZ_Raw-(sum_XSquare_Raw+sum_ZSquare_Raw)*sum_Z_Raw;

a = (H*D-E*G)/(C*G-D*D);
b = (H*C-E*D)/(D*D-G*C);
c = -((sum_XSquare_Raw+sum_ZSquare_Raw)+a*sum_X_Raw+b*sum_Z_Raw)/N;

p(1) = -0.5*a;
p(2) = -0.5*b;
p(3) = 0.5*sqrt(a*a+b*b-4*c);
% m=max(abs(x.^2+z.^2+x.*a+z.*b+c));
mm=0;
for i=1:1:size(XZ,1)
    mm=mm+abs(pdist([p(1:2);XZ(i,1:2)])-p(3));
end
m=mm/size(XZ,1)/p(3);
end

end